<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>基础知识</title>
</head>
<body>
	<script type="text/javascript">
		//获取2017-06-10格式的日期？
		function formatDate(dt) {
			if(!dt) {
				dt = new Date()
			}
			var year = dt.getFullYear()
			var month = dt.getMonth()
			var date = dt.getDate()
			if(month < 10) {
				//强制类型转换
				month = '0' + month
			}
			if(date < 10) {
				//强制类型转换
				date = '0' + date
			}
			//强制类型转换
			return year + '-' + month + '-' +date
		}
		var dt = new Date()
		var formatDate = formatDate(dt)
		console.log(formatDate)
	</script>
	<script type="text/javascript">
		//获取随机数，要求长度一直的字符串格式
		var random = Math.random()
		var random = random + '0000000000' //后面加上10个0
		var random = random.slice(0, 10)
		console.log(random)
	</script>
	<script type="text/javascript">
		//写一个能遍历对象和数组的通用forEach函数
		function forEach(obj, fn){
			var key
			if(obj instanceof Array) {
				//判断是不是数组
				obj.forEach(function(item, index){
					fn(index, item)
				})
			} else {
				//不是数组就是对象
				for(key in obj) {
					fn(key, obj[key])
				}
			}
		}
		var arr = [1,2,3]
		forEach(arr, function(index, item){

		})
		var obj = {x:100, y:200}
		forEach(obj, function(key, value){
			
		})
	</script>
</body>
</html>